
const express = require('express');
const server = express();
server.use(express.static('dist'));
const fs = require('fs')
const path = require('path')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')
const template = fs.readFileSync(resolve('./dist/index.html'), 'utf-8')
const bundle = fs.readFileSync(resolve('./dist/entry-server.js'), 'utf-8');
const renderer = createBundleRenderer(bundle, {
  template
});
server.get('*', (request, response) => {
  const context = {
    title: 'Vue HN 2.0', // default title
    url: request.url
  }
  renderer.renderToString(context).then(html => {
    response.send(html)
  }, err => {
    console.log(err)
  }).catch(function (e) {
    console.log(e)
  })


})
server.listen(2333)
console.log('listen2333成功')